<template>
  <div>

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="6" :sm="8">
            <a-form-item :label="$t('m.system.message.entity.esTitle')">
              <a-input placeholder="" v-model="queryParam.esTitle"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item :label="$t('m.system.message.entity.esContent')">
              <a-input placeholder="" v-model="queryParam.esContent"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :md="6" :sm="8">
              <a-form-item :label="$t('m.system.message.entity.esReceiver')">
                <a-input placeholder="" v-model="queryParam.esReceiver"></a-input>
              </a-form-item>
            </a-col>
          </template>
          <a-col :md="6" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">{{ $t('m.common.button.query') }}</a-button>
              <a-button type="default" @click="searchReset" icon="reload" style="margin-left: 8px">{{ $t('m.common.button.reset') }}</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? this.$t('m.common.button.fold') : this.$t('m.common.button.expand') }}
                <ych-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">{{ $t('m.common.button.add') }}</a-button>
      <a-button @click="batchDel" type="default"  icon="delete">{{ $t('m.common.button.delete') }}</a-button>
      <a-button type="default" icon="download" @click="handleExportXls($t('m.system.message.other.export_message_filename'))">{{ $t('m.common.button.export') }}</a-button>
      <a-upload  name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl"
                @change="handleImportExcel">
        <a-button type="default" icon="import">{{ $t('m.common.button.import') }}</a-button>
      </a-upload>
    </div>

    <!-- table区域-begin -->
    <div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">
        <template slot="serialNum" slot-scope="text,record,index">
          {{(ipagination.current-1) * ipagination.pageSize + parseInt(index) + 1}}
        </template>
        <span slot="sendTypeSlot" slot-scope="text" color="blue">
            <a-tag :color="text | sendTypeFilter">
              {{ sendTypeFormat(text) }}
            </a-tag>
        </span>
        <span slot="sendStatusSlot" slot-scope="text" color="blue">
            <a-tag :color="text | sendStatusFilter">
              {{ sendStatusFormat(text) }}
            </a-tag>
        </span>

        <span slot="action" slot-scope="text, record">
          <a href="javascript:;" @click="handleDetail(record)">{{$t('m.common.title.detail')}}</a>
          <a-divider type="vertical" v-show="show"/>
          <a v-show="show" href="javascript:;" @click="handleEdit(record)">{{ $t('m.common.button.update') }}</a>
          <a-divider type="vertical"/>
          <a-popconfirm :title="$t('m.common.tip.delete_confirm')" @confirm="() => handleDelete(record.id)">
            <a>{{ $t('m.common.button.delete') }}</a>
          </a-popconfirm>
        </span>

      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <sysMessage-modal ref="modalForm" @ok="modalFormOk"></sysMessage-modal>
  </div>
</template>

<script>

  import SysMessageModal from './modules/SysMessageModal'
  import {YcListMixin} from '@/mixins/YcListMixin'
  import YchConstant from "@/api/YchConstant";

  export default {
    name: "SysMessageList",
    mixins: [YcListMixin],
    components: {
      SysMessageModal,
    },
    data() {
      return {
        description: '消息管理页面',
        // 新增修改按钮是否显示
        show: false,
        // 表头
        columns: [
          {
            title:this.$t('m.common.label.number'),
            dataIndex: '',
            key: 'rowIndex',
            width: 50,
            align: "center",
            scopedSlots: { customRender: 'serialNum' },
          },
          {
            title: this.$t('m.system.message.entity.esTitle'),
            align: "center",
            dataIndex: 'esTitle',
            width:150
          },
          {
            title: this.$t('m.system.message.entity.esType'),
            align: 'center',
            dataIndex: 'esType',
            scopedSlots: { customRender: 'sendTypeSlot' },
          },
          {
            title: this.$t('m.system.message.entity.esReceiver'),
            align: "center",
            dataIndex: 'esReceiver'
          },
          {
            title: this.$t('m.system.message.entity.esSendNum'),
            align: "center",
            dataIndex: 'esSendNum'
          },
          {
            title:this.$t('m.system.message.entity.esSendStatus'),
            align: 'center',
            dataIndex: 'esSendStatus',
            scopedSlots: { customRender: 'sendStatusSlot' },
          },
          {
            title: this.$t('m.system.message.entity.esSendTime'),
            align: "center",
            dataIndex: 'esSendTime'
          },

          {
            title: this.$t('m.common.label.operate'),
            dataIndex: 'action',
            align: "center",
            scopedSlots: {customRender: 'action'},
            width: 240
          }
        ],
        url: {
          list: YchConstant.PREFIX_SYSTEM + "/message/sysMessage/list",
          delete: YchConstant.PREFIX_SYSTEM + "/message/sysMessage/delete",
          deleteBatch: YchConstant.PREFIX_SYSTEM + "/message/sysMessage/deleteBatch",
          exportXlsUrl: YchConstant.PREFIX_SYSTEM + "/message/sysMessage/exportExcel",
          importExcelUrl: YchConstant.PREFIX_SYSTEM + "/message/sysMessage/importExcel",
        },
      }
    },
    filters: {
        sendTypeFilter (type) {
          let value = '#108ee9'
          if (type === 1) {
            value = '#2db7f5'
          } else if (type === 2) {
            value = '#87d068'
          }
          return value
        },
        sendStatusFilter (type) {
          let value = '#108ee9'
          if (type === 0) {
            value = '#2db7f5'
          } else if (type === 1) {
            value = '#87d068'
          }
          return value
        },
    },
    computed: {
      importExcelUrl: function () {
        return `${bootConfig[process.env.NODE_ENV].VUE_APP_API}${this.url.importExcelUrl}`;
      }
    },
    methods: {
      sendTypeFormat(text){
        if (text == 1) {
          return this.$t('m.system.message.other.esType_option1')
        } else if (text == 2) {
          return this.$t('m.system.message.other.esType_option2')
        } else if (text == 5) {
          return this.$t('m.system.message.other.esType_option5')
        } else {
          return text
        }
      },
      sendStatusFormat(text){
        if (text == 0) {
          return this.$t('m.system.message.other.status_option0')
        } else if (text == 1) {
          return this.$t('m.system.message.other.status_option1')
        }else if (text == 2) {
           return this.$t('m.system.message.other.status_option2')
        } else {
          return text
        }
      },
    }
  }
</script>
<style lang="less" scoped>
  /** Button按钮间距 */
  .ant-btn {
    margin-left: 3px
  }

  .ant-card-body .table-operator {
    margin-bottom: 18px;
  }

  .ant-table-tbody .ant-table-row td {
    padding-top: 15px;
    padding-bottom: 15px;
  }

  .anty-row-operator button {
    margin: 0 5px
  }

  .ant-btn-danger {
    background-color: #ffffff
  }

  .ant-modal-cust-warp {
    height: 100%
  }

  .ant-modal-cust-warp .ant-modal-body {
    height: calc(100% - 110px) !important;
    overflow-y: auto
  }

  .ant-modal-cust-warp .ant-modal-content {
    height: 90% !important;
    overflow-y: hidden
  }
</style>
